﻿@inherits BaseChartComponent

<CascadingValue Value="this" IsFixed="true">
    @ChildContent
</CascadingValue>

@code {
    private IDictionary<string, object> axisLabel = new Dictionary<string, object>();

    private IDictionary<string, object> axisLine = new Dictionary<string, object>();

    private IDictionary<string, object> axisTick = new Dictionary<string, object>();

    private IDictionary<string, object> splitLine = new Dictionary<string, object>();

    private IDictionary<string, object> splitArea = new Dictionary<string, object>();

    private IList<Dictionary<string, object>> radarIndicator = new List<Dictionary<string, object>>();

    protected override string ComponentName => "radar";

    #region 参数

    /// <summary>
    /// 组件 ID
    /// </summary>
    [Parameter]
    public string? id { get; set; }

    /// <summary>
    /// 所有图形的 zlevel 值
    /// </summary>
    [Parameter]
    public int? zlevel { get; set; }

    /// <summary>
    /// 组件的所有图形的z值
    /// </summary>
    [Parameter]
    public int? z { get; set; }

    /// <summary>
    /// 中心（圆心）坐标，数组的第一项是横坐标，第二项是纵坐标
    /// </summary>
    [Parameter]
    public object[]? center { get; set; }

    /// <summary>
    /// 半径
    /// </summary>
    [Parameter]
    public dynamic? radius { get; set; }

    /// <summary>
    /// 坐标系起始角度，也就是第一个指示器轴的角度
    /// </summary>
    [Parameter]
    public int? startAngle { get; set; }

    /// <summary>
    /// 指示器名称和指示器轴的距离
    /// </summary>
    [Parameter]
    public int? nameGap { get; set; }

    /// <summary>
    /// 指示器轴的分割段数
    /// </summary>
    [Parameter]
    public int? splitNumber { get; set; }

    /// <summary>
    /// 雷达图绘制类型，支持 'polygon' 和 'circle'
    /// </summary>
    [Parameter]
    public string? shape { get; set; }

    /// <summary>
    /// 是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度
    /// </summary>
    [Parameter]
    public bool? scale { get; set; }

    /// <summary>
    /// 坐标轴是否是静态无法交互
    /// </summary>
    [Parameter]
    public bool? silent { get; set; }

    /// <summary>
    /// 坐标轴的标签是否响应和触发鼠标事件，默认不响应
    /// </summary>
    [Parameter]
    public bool? triggerEvent { get; set; }

    /// <summary>
    /// 雷达图的指示器，用来指定雷达图中的多个变量（维度）
    /// </summary>
    [Parameter]
    public object[]? indicator { get; set; }

    #endregion

    protected override Task SetParametersAsync()
    {
        if (!string.IsNullOrEmpty(id))
            FillSetting("id", id);

        if (zlevel.HasValue)
            FillSetting("zlevel", zlevel.Value);

        if (z.HasValue)
            FillSetting("z", z.Value);

        if (center != null && center.Length > 0)
            FillSetting("center", center);

        if (radius != null)
            FillSetting("radius", radius);

        if (startAngle.HasValue)
            FillSetting("startAngle", startAngle.Value);

        if (nameGap.HasValue)
            FillSetting("nameGap", nameGap.Value);

        if (scale.HasValue)
            FillSetting("scale", scale.Value);

        if (!string.IsNullOrEmpty(shape))
            FillSetting("shape", shape);

        if (splitNumber.HasValue)
            FillSetting("splitNumber", splitNumber.Value);

        if (silent.HasValue)
            FillSetting("silent", silent.Value);

        if (triggerEvent.HasValue)
            FillSetting("triggerEvent", triggerEvent.Value);

        if (indicator != null && indicator.Length > 0)
            FillSetting("indicator", indicator);

        return Task.CompletedTask;
    }

    public void SetAxisLabel(Action<IDictionary<string, object>> action)
    {
        FillSetting("axisLabel", axisLabel);
        action?.Invoke(axisLabel);
    }

    public void SetAxisLine(Action<IDictionary<string, object>> action)
    {
        FillSetting("axisLine", axisLine);
        action?.Invoke(axisLine);
    }

    public void SetAxisTick(Action<IDictionary<string, object>> action)
    {
        FillSetting("axisTick", axisTick);
        action?.Invoke(axisTick);
    }

    public void SetSplitLine(Action<IDictionary<string, object>> action)
    {
        FillSetting("splitLine", splitLine);
        action?.Invoke(splitLine);
    }

    public void SetSplitArea(Action<IDictionary<string, object>> action)
    {
        FillSetting("splitArea", splitArea);
        action?.Invoke(splitArea);
    }

    public void SetRadarIndicator(Action<IList<Dictionary<string, object>>> action)
    {
        FillSetting("indicator", radarIndicator);
        action?.Invoke(radarIndicator);
    }

    public void RemoveRadarIndicator(Dictionary<string, object> item)
    {
        if (radarIndicator.Contains(item))
            radarIndicator.Remove(item);
    }
}
